import sys
from pathlib import Path
import importlib

# 添加外部库路径
external_dir = Path(__file__).parent / "lib/CosyVoice"
if str(external_dir) not in sys.path:
    sys.path.insert(0, str(external_dir))

try:
    # 导入主模块 `cosyvoice`
    cosyvoice = importlib.import_module("cosyvoice")
    # 逐级导入子模块 `cli.cosyvoice`
    cli_cosyvoice = importlib.import_module("cosyvoice.cli.cosyvoice")
    # 获取类 `CosyVoice2`
    CosyVoice2 = getattr(cli_cosyvoice, "CosyVoice2")
except (ImportError, AttributeError) as e:
    raise RuntimeError("导入失败，请检查目录结构或依赖！") from e
